/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sbbs.ingite.sample2;

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.lang.IgniteFuture;

/**
 *
 * @author Administrator
 */
public class Sample2 {

    public static void main(String[] args) {
        try (Ignite ignite = Ignition.start("example-ignite.xml")) {
            IgniteCache<Integer, String> cache = ignite.getOrCreateCache("myCacheName");
            // Store keys in cache (values will end up on different cache nodes).
            for (int i = 0; i < 10; i++) {
                cache.put(i, Integer.toString(i));
            }
            for (int i = 0; i < 10; i++) {
                System.out.println("Got [key=" + i + ", val=" + cache.get(i) + ']');
            }
            for (int i = 0; i < 10; i++) {
                IgniteFuture<String> ifu = cache.getAsync(i);
                while (ifu.isDone()) {
                    System.out.println("Async Got [key=" + i + ", val=" + ifu.get() + ']');
                    break;
                }
            }

//            // Put-if-absent which returns previous value.
//            Integer oldVal = cache.getAndPutIfAbsent("Hello", 11);
//// Put-if-absent which returns boolean success flag.
//            boolean success = cache.putIfAbsent("World", 22);
//// Replace-if-exists operation (opposite of getAndPutIfAbsent), returns previous value.
//            oldVal = cache.getAndReplace("Hello", 11);
//// Replace-if-exists operation (opposite of putIfAbsent), returns boolean success flag.
//            success = cache.replace("World", 22);
//// Replace-if-matches operation.
//            success = cache.replace("World", 2, 22);
//// Remove-if-matches operation.
//            success = cache.remove("Hello", 1);
            while (true) {

            }
        }

    }
}
